/**
 * ---------------------------
 * Time: 2017/8/6 16:17.
 * Author: Cangshi
 * View: http://palerock.cn
 * ---------------------------
 */
require.config({
    paths: {
        'angular': '../lib/anjular/angular',
        'angular-route': '../lib/anjular/angular-route',
        'angular-async-loader': '../lib/anjular/angular-async-loader',
        'zepto': '../lib/sui/zepto',
        'sui': '../lib/sui/sm',
        'suiExtend': '../lib/sui/sm-extend.min',
        'dexie': '../lib/dexie/dexie',
        'simply-hook': '../lib/simply-hook/simply-hook',
        'app': 'angular/app',
        'app-plus': 'angular/app-plus',
        'app-page-admin': 'angular/page-admin',
        // 'controllers': '../src/common/controller/controllers',
        'bootstrap': '../src/common/bootstrap',
        'loader': 'angular/angular-loader',
        'jscolor': '../lib/color/jscolor',
        'css-loader': '../lib/css-loader/css-loader'
    },
    shim: {
        'dexie': {
            exports: 'Dexie'
        },
        'angular': {
            exports: 'angular'
        },
        'zepto': {
            exports: '$'
        },
        'jscolor': {
            exports: 'jscolor'
        },
        'sui': {
            deps: ['zepto']
        },
        'suiExtend': {
            deps: ['sui']
        },
        'angular-route': {
            deps: ['angular']
        },
        'bootstrap': {
            deps: ['app', 'loader']
        }
    }
});

require(['zepto'], function ($) {
    // 关闭sui的默认路由
    $.config = {router: false, autoInit: false};
});

require(
    ['angular', 'app', 'bootstrap', 'zepto', 'simply-hook', 'app-plus', 'app-page-admin'],
    function (angular, app, bootstrapResult, $, simplyHook) {
        angular.element(document).ready(function () {
            // 手动启用angular
            angular.bootstrap(document, ['app']);
            angular.element(document).find('html').addClass('ng-app');

            // 注册沉浸状态栏style
            var styleEle = document.createElement('style');
            styleEle.innerHTML =
                'header.bar-nav{padding-top:' + app.immersed + 'px;height:' + (app.navHeight + app.immersed) + 'px;}' +
                '.bar-nav:not(.transparent) ~ .content{top:' + (app.navHeight + app.immersed) + 'px;}';
            document.head.appendChild(styleEle);
        });

        // 注册一些基础事件（aop操作）
        simplyHook.hook($, 'actions', {
            after: function () {
                $('.modal-overlay-visible').click(function () {
                    app.backEvent();
                    $(this).unbind('click');
                });
            }
        });


    }
);